import { loadUsersJson,saveUser,deleteUser,editUserInfoNew,resetUserPassword} from '@/services/geographic';
import { queryCurrent,getUserList,getRolesByCreateUserPage,addUsers,delUsers,resetPassword,editUser,getUsersById} from '@/services/user';
export default {
  namespace:'management',
  state: {
    total:0,
    items:[],
    loading:true
  },
  effects: {
    *getUsers({ payload, callback }, { call, put }) {
      const response = yield call(getUserList, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *getRoleLists({ payload, callback }, { call, put }) {
      const response = yield call(getRolesByCreateUserPage, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *addUser({ payload, callback }, { call, put }) {
      const response = yield call(addUsers, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *editUser({ payload, callback }, { call, put }) {
      const response = yield call(editUser, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *resetUser({ payload, callback }, { call, put }) {
      const response = yield call(resetPassword, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *delUser({ payload, callback }, { call, put }) {
      const response = yield call(delUsers, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *queryUser({ payload, callback }, { call, put }) {
      const response = yield call(queryCurrent, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *getUserById({ payload, callback }, { call, put }) {
      const response = yield call(getUsersById, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    }
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
